package com.saver.service;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import com.saver.core.util.Constantes;

/**
 * Created by HGonzales.
 */
public class SMSListenerService extends Service {

    public static SMSListenerService serviceInstance = null;

    private BroadcastReceiver smsBroadcastReceiver;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(smsBroadcastReceiver);
        serviceInstance = null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Constantes.ACCION_SMS_RECIBIDO);
        intentFilter.setPriority(Integer.MAX_VALUE);
        smsBroadcastReceiver = new SMSBroadcastReceiver(this);
        registerReceiver(smsBroadcastReceiver, intentFilter);
        serviceInstance = this;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    public static boolean isRunning() {
        return serviceInstance != null;
    }
}